package com.ea.controller.front;

import com.ea.api.controller.user.FrontElectricGoodsInfoApi;
import com.ea.common.enums.OperationResultCode;
import com.ea.common.exception.ServiceException;
import com.ea.common.response.JsonResult;
import com.ea.common.util.TypeConversionToJson;
import com.ea.domain.dto.StoreEvaluateDTO;
import com.ea.domain.query.FrontElectricGoodsQueryDTO;
import com.ea.domain.vo.ElectricGoodsVO;
import com.ea.domain.vo.ElectricGoodsSkuVO;
import com.ea.domain.vo.OrderDetailVO;
import com.ea.service.IFrontElectricGoodsInfoService;
import com.ea.service.IStoreEvaluateInfoService;
import com.ea.service.ISysBaseDictionaryService;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author NAME-L
 * @Description TODO
 * @className ElectricGoodsFrontController
 * @date 2022-12-06 20:51:08
 */
@RestController
@RequestMapping("/electric/front/store")
public class ElectricGoodsFrontController implements FrontElectricGoodsInfoApi {

    @Autowired
    private IFrontElectricGoodsInfoService electricGoodsInfoService;

    @Autowired
    private IStoreEvaluateInfoService evaluateInfoService;



    @Override
    @PostMapping("/goods/list")
    public JsonResult getElectricGoodsList(@RequestBody FrontElectricGoodsQueryDTO queryDTO) {
        PageInfo<ElectricGoodsVO> goodsList = electricGoodsInfoService.getGoodsList(queryDTO);
        return JsonResult.doSuccessful(goodsList);
    }

    @Override
    @GetMapping("/goods/sku")
    public JsonResult getElectricGoodsSku(@RequestParam("goodsId") Long goodsId) {
        if (goodsId == null) {
            throw new ServiceException(OperationResultCode.PARAMETER_ERROR);
        }
        Map<String, String> goodsSkuMap = electricGoodsInfoService.getSkuInfoByGoodsId(goodsId);
        return JsonResult.doSuccessful(goodsSkuMap);
    }

    @Override
    @GetMapping("/goods/sku/detail")
    public JsonResult getElectricGoodsSkuDetail( @RequestParam("skuId") Long skuId) {
        if (skuId == null) {
            throw new ServiceException(OperationResultCode.PARAMETER_ERROR);
        }
        ElectricGoodsSkuVO skuInfoBySkuId = electricGoodsInfoService.getSkuInfoBySkuId(skuId);
        return JsonResult.doSuccessful(skuInfoBySkuId);
    }

    @Override
    @PostMapping("/goods/hot")
    public JsonResult getHotElectricGoods() {
        List<ElectricGoodsVO> hotGoodsCache = electricGoodsInfoService.getHotGoodsCache();
        return JsonResult.doSuccessful(hotGoodsCache);
    }

    @Override
    @GetMapping("/goods/evaluate")
    public JsonResult getElectricGoodsEvaluate(@RequestParam("goodsId")Long goodsId) {
        if (goodsId == null) {
            throw new ServiceException(OperationResultCode.PARAMETER_ERROR);
        }
        return JsonResult.doSuccessful(evaluateInfoService.listEvaluateByGoodsId(goodsId));
    }

    @Override
    @PostMapping("/goods/question")
    public JsonResult askQuestionToAnyOne() {
        return null;
    }

}
